package cn.ronghuanet.car.controller;

import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.PageInfo;
import cn.ronghuanet.car.doc.CarDoc;
import cn.ronghuanet.car.query.CarSearchQuery;
import cn.ronghuanet.car.service.ICarSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/car/search")
public class CarSearchController {

    @Autowired
    private ICarSearchService carSearchService;

    @PostMapping
    public AjaxResult search(@RequestBody CarSearchQuery query){
        // 门户网站在做搜索的时候,要返回分页的数据(当前页数据/总条数),并且还要返回 车辆类型ID和名字
        // 方案一:在AjaxResult中再多写一个objData, 问题:如果以后要再次返回其他数据的话,要再次修改AjaxResult
        // 方案二:在PageInfo中添加字段进行返回
        // 从es中进行查询
        PageInfo<CarDoc> pageInfo = carSearchService.search(query);
        return AjaxResult.success(pageInfo);
    }

}
